import { RootState } from "@/types/store"
import { useEffect } from "react"
import { useDispatch, useSelector } from "react-redux"

function useInitialState<K extends keyof RootState>(actionFn:()=>void,ReducerState:K){
    const dispatch=useDispatch()
    useEffect(()=>{
        dispatch(actionFn())
    // eslint-disable-next-line react-hooks/exhaustive-deps
    },[dispatch])
    const userProfile = useSelector((state:RootState)=>state[ReducerState])
    return userProfile
}

export default useInitialState